using MicroMsg.Common.Event;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class ProfileInfoWithHeadCtrl : ProfileInfoItemBase
	{
		public delegate void ListItemClick(object sender, object object_0);
		private const string TAG = "ProfileInfoWithHeadCtrl";
		private const int cNMaxCacheCnt = 3;
		private bool mBIsFirstLoaded = true;
		private EventWatcher mWatchxxx;
		private object mObjectWatcher = new object();
		private static List<ProfileInfoWithHeadCtrl> sItemsCached = new List<ProfileInfoWithHeadCtrl>();
		internal StackPanel LayoutRoot;
		internal TextBlock txtAreaTitle;
		internal EmojiText txtNicks;
		internal EmojiText txtStaticText;
		internal Image imgHead;
		private bool _contentLoaded;
		public event ProfileInfoWithHeadCtrl.ListItemClick ItemClick;
		public ProfileInfoWithHeadCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Control_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Control_Unloaded));
			base.set_Visibility(1);
		}
		private void Control_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void Control_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void registerEvent()
		{
			if (this.mWatchxxx == null)
			{
				this.mWatchxxx = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.Onxxx));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchxxx != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
				this.mWatchxxx = null;
			}
		}
		private void Onxxx(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
		}
		protected override void RefreshItem()
		{
			if (base.InfoData == null)
			{
				base.set_Visibility(1);
				return;
			}
			this.txtStaticText.Text = base.InfoData.mStrInfo2;
			this.txtStaticText.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
			this.txtStaticText.InvalidateMeasure();
			this.txtNicks.set_MaxWidth(380.0 - this.txtNicks.get_Margin().get_Right() - this.txtStaticText.get_DesiredSize().get_Width());
			this.txtAreaTitle.set_Text(base.InfoData.mStrTitle);
			this.txtNicks.Text = base.InfoData.mStrInfo1;
			this.imgHead.set_Source(base.InfoData.mBitMapImg);
			base.set_Visibility(0);
		}
		public void SetHead(BitmapImage bitmapImage_0)
		{
			this.imgHead.set_Source(bitmapImage_0);
		}
		public void SetContent(string strTitle, string strInfo1, string strInfo2 = null, ProfileInfoKind infoKind = ProfileInfoKind.Kind_None)
		{
			ProfileInfoData infoData = new ProfileInfoData
			{
				mStrTitle = strTitle,
				mStrInfo1 = strInfo1,
				mStrInfo2 = strInfo2,
				mInfoKind = infoKind
			};
			base.InfoData = infoData;
		}
		public override void Collect()
		{
			base.Collect();
			base.InfoData = null;
			this.txtAreaTitle.set_Text("");
			this.txtNicks.Text = "";
			this.txtStaticText.Text = "";
			this.imgHead.set_Source(null);
			base.set_Visibility(1);
		}
		public static ProfileInfoWithHeadCtrl GetOneItem()
		{
			if (ProfileInfoWithHeadCtrl.sItemsCached != null && ProfileInfoWithHeadCtrl.sItemsCached.get_Count() != 0)
			{
				ProfileInfoWithHeadCtrl profileInfoWithHeadCtrl = Enumerable.First<ProfileInfoWithHeadCtrl>(ProfileInfoWithHeadCtrl.sItemsCached);
				ProfileInfoWithHeadCtrl.sItemsCached.RemoveAt(0);
				if (profileInfoWithHeadCtrl.get_Parent() == null)
				{
					return profileInfoWithHeadCtrl;
				}
			}
			return new ProfileInfoWithHeadCtrl();
		}
		public static int GetCacheCnt()
		{
			if (ProfileInfoWithHeadCtrl.sItemsCached == null)
			{
				return 0;
			}
			return ProfileInfoWithHeadCtrl.sItemsCached.get_Count();
		}
		public static void PushOneItem(ProfileInfoWithHeadCtrl item)
		{
			if (item == null)
			{
				return;
			}
			if (ProfileInfoWithHeadCtrl.sItemsCached == null)
			{
				ProfileInfoWithHeadCtrl.sItemsCached = new List<ProfileInfoWithHeadCtrl>();
			}
			if (item.get_Parent() != null)
			{
				Panel panel = item.get_Parent() as Panel;
				if (panel != null)
				{
					panel.get_Children().Remove(item);
				}
			}
			item.Collect();
			if (ProfileInfoWithHeadCtrl.sItemsCached.get_Count() >= 3)
			{
				return;
			}
			ProfileInfoWithHeadCtrl.sItemsCached.Add(item);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/ProfileInfo/ProfileInfoWithHeadCtrl.xaml", 2));
			this.LayoutRoot = (StackPanel)base.FindName("LayoutRoot");
			this.txtAreaTitle = (TextBlock)base.FindName("txtAreaTitle");
			this.txtNicks = (EmojiText)base.FindName("txtNicks");
			this.txtStaticText = (EmojiText)base.FindName("txtStaticText");
			this.imgHead = (Image)base.FindName("imgHead");
		}
	}
}
